---
title: "slider"
icon: "sliders"
description: ""
---

```python
slider(
    label: str,
    min_val: float = 0.0,
    max_val: float = 100.0,
    step: float = 1.0,
    default: Optional[float] = None,
    size: float = 1.0,
) -> float:
```

The `slider` function adds an interactive slider to your app, enabling users to input numerical values within a specified range. This is especially useful for dynamic controls, such as selecting a range or adjusting parameters.

## Parameters

- **`label`** _(str)_: The label displayed next to the slider, indicating its purpose.
- **`min_val`** _(float)_: The minimum value the slider can take.
- **`max_val`** _(float)_: The maximum value the slider can take.
- **`step`** _(int)_: The step size between values on the slider.
- **`default`** _(float)_: _(Optional)_ The initial/default value of the slider.
- **`size`** _(float)_: _(Optional)_ The width of the component in a row. Defaults to `1.0` (full row). See the [Layout Guide](/layout/guide) for details.

<Frame>
<img
  className="block dark:hidden"
  src="/images/slider.png"
  alt="Hero Light"
/>
</Frame>

## Returns

- `float` containing the current value.

## Usage Example

Here’s an example of how to add a slider to your app:

```python
from preswald import slider

# Create a slider for selecting the number of rows to display
value = slider(
    label="Rows to Display",
    min_val=1,
    max_val=100,
    step=10,
    default=20
)

# Use the selected value
print(f"Slider selected value: {value}")
```

### Key Features

1. **Customizable Range**: Define the range of values with `min_val` and `max_val`.
2. **Adjustable Precision**: Control increments using the `step` parameter.
3. **Default Selection**: Set a sensible starting point with the `default` parameter.
4. **Real-Time Input**: Values update dynamically as the user interacts with the slider.

### Why Use `slider`?

Sliders provide an intuitive way to capture numerical input, enhancing user experience by making the interface interactive and responsive.

Simplify user input with the `slider`! 🛠️
